import { Collapse } from "antd";
import { LinterConfig } from "./config";
import Accessibility from "./Accessibility";
import Complexity from "./Complexity";
import Correctness from "./Correctness";
import Performance from "./Performance";
import Security from "./Security";
import Style from "./Style";
import Suspicious from "./Suspicious";
import Nursery from "./Nursery";

interface LinterProps {
    linter?: LinterConfig;
    onChange: (linter: LinterConfig) => void;
}


export default function Linter(props: LinterProps) {
    return (
        <Collapse accordion>
            <Collapse.Panel header="无障碍(Accessibility)" key="accessibility">
                <p>规则侧重于防止无障碍问题</p>
                <p>Rules focused on preventing accessibility problems.</p>
                <Accessibility accessibility={props.linter?.rules?.accessibility ?? {}} onChange={accessibility => {
                    let linter = props.linter;
                    if (linter == undefined) {
                        linter = {};
                    }
                    if (linter.rules == undefined) {
                        linter.rules = {};
                    }
                    linter.rules.accessibility = accessibility;
                    props.onChange(linter);
                }} />
            </Collapse.Panel>
            <Collapse.Panel header="复杂性(Complexity)" key="complexity">
                <p>专注于检查可以简化复杂代码的规则。</p>
                <p>Rules that focus on inspecting complex code that could be simplified.</p>
                <Complexity complexity={props.linter?.rules?.complexity ?? {}} onChange={complexity => {
                    let linter = props.linter;
                    if (linter == undefined) {
                        linter = {};
                    }
                    if (linter.rules == undefined) {
                        linter.rules = {};
                    }
                    linter.rules.complexity = complexity;
                    props.onChange(linter);
                }} />
            </Collapse.Panel>
            <Collapse.Panel header="正确性(Correctness)" key="correctness">
                <p>检测保证不正确或无用的代码的规则。</p>
                <p>Rules that detect code that is guaranteed to be incorrect or useless.</p>
                <Correctness correctness={props.linter?.rules?.correctness ?? {}} onChange={correctness => {
                    let linter = props.linter;
                    if (linter == undefined) {
                        linter = {};
                    }
                    if (linter.rules == undefined) {
                        linter.rules = {};
                    }
                    linter.rules.correctness = correctness;
                    props.onChange(linter);
                }} />
            </Collapse.Panel>
            <Collapse.Panel header="性能(Performance)" key="performance">
                <p>捕捉规则的方法可以使代码运行得更快，或者通常更高效。</p>
                <p>Rules catching ways your code could be written to run faster, or generally be more efficient.</p>
                <Performance performance={props.linter?.rules?.performance ?? {}} onChange={performance => {
                    let linter = props.linter;
                    if (linter == undefined) {
                        linter = {};
                    }
                    if (linter.rules == undefined) {
                        linter.rules = {};
                    }
                    linter.rules.performance = performance;
                    props.onChange(linter);
                }} />
            </Collapse.Panel>
            <Collapse.Panel header="安全(Security)" key="security">
                <p>检测潜在安全缺陷的规则。</p>
                <p>Rules that detect potential security flaws.</p>
                <Security security={props.linter?.rules?.security ?? {}} onChange={security => {
                    let linter = props.linter;
                    if (linter == undefined) {
                        linter = {};
                    }
                    if (linter.rules == undefined) {
                        linter.rules = {};
                    }
                    linter.rules.security = security;
                    props.onChange(linter);
                }} />
            </Collapse.Panel>
            <Collapse.Panel header="代码风格(Style)" key="style">
                <p>强制使用一致且惯用的代码编写方式的规则。强制使用一致且惯用的代码编写方式的规则</p>
                <p>Rules enforcing a consistent and idiomatic way of writing your code.</p>
                <Style style={props.linter?.rules?.style ?? {}} onChange={style => {
                    let linter = props.linter;
                    if (linter == undefined) {
                        linter = {};
                    }
                    if (linter.rules == undefined) {
                        linter.rules = {};
                    }
                    linter.rules.style = style;
                    props.onChange(linter);
                }} />
            </Collapse.Panel>
            <Collapse.Panel header="可疑性(Suspicious)" key="suspicious">
                <p>检测可能不正确或无用的代码的规则。</p>
                <p>Rules that detect code that is likely to be incorrect or useless.</p>
                <Suspicious suspicious={props.linter?.rules?.suspicious ?? {}} onChange={suspicious => {
                    let linter = props.linter;
                    if (linter == undefined) {
                        linter = {};
                    }
                    if (linter.rules == undefined) {
                        linter.rules = {};
                    }
                    linter.rules.suspicious = suspicious;
                    props.onChange(linter);
                }} />
            </Collapse.Panel>
            <Collapse.Panel header="实验性(Nursery)" key="nursery">
                <p>开发中的规则。</p>
                <p>New rules that are still under development.</p>
                <Nursery nursery={props.linter?.rules?.nursery ?? {}} onChange={nursery => {
                    let linter = props.linter;
                    if (linter == undefined) {
                        linter = {};
                    }
                    if (linter.rules == undefined) {
                        linter.rules = {};
                    }
                    linter.rules.nursery = nursery;
                    props.onChange(linter);
                }} />
            </Collapse.Panel>
        </Collapse>
    );
}